package com.mall.admin.controller;

import com.mall.admin.service.SmsFlashPromotionSessionService;
import com.mall.commons.utils.R;
import com.mall.domain.SmsFlashPromotionSession;
import com.mall.vo.FlashSessionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/flashSession")
public class SmsFlashPromotionSessionController {

    @Autowired
    private SmsFlashPromotionSessionService smsFlashPromotionSessionService;

    //添加场次
    @PostMapping("/create")
    public R create(@RequestBody SmsFlashPromotionSession smsFlashPromotionSession){
        smsFlashPromotionSessionService.create(smsFlashPromotionSession);
        return R.success("添加场次",null);
    }

    //删除场次
    @PostMapping("/delete/{id}")
    public R delete(@PathVariable Long id){
        smsFlashPromotionSessionService.delete(id);
        return R.success("删除场次",null);
    }

    //获取全部场次
    @GetMapping("/list")
    public R list(){
        List<SmsFlashPromotionSession> sfpsList = smsFlashPromotionSessionService.list();
        return R.success("获取全部场次",sfpsList);
    }

    //获取全部可选场次及其数量
    @GetMapping("/selectList")
    public R selectList(Long flashPromotionId){
        List<FlashSessionVo> voList = smsFlashPromotionSessionService.selectList(flashPromotionId);
        return R.success("全部可选场次",voList);
    }

    //修改启用状态
    @PostMapping("/update/status/{id}")
    public R updateStatus(@PathVariable Long id,Integer status){
        smsFlashPromotionSessionService.updateStatus(id,status);
        return R.success("修改启用状态",null);
    }

    //修改场次
    @PostMapping("/update/{id}")
    public R update(@PathVariable Long id,SmsFlashPromotionSession smsFlashPromotionSession){
        smsFlashPromotionSessionService.update(id,smsFlashPromotionSession);
        return R.success("修改场次",null);
    }

    //获取场次详情
    @GetMapping("/{id}")
    public R find(@PathVariable Long id){
        SmsFlashPromotionSession smsFlashPromotionSession = smsFlashPromotionSessionService.find(id);
        return R.success("获取场次详情",smsFlashPromotionSession);
    }

}
